<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<script type="text/javascript">
	window.onload = function(){
		if(dojo.widget.byId("employeeList").getText() != ""){
			dojo.widget.byId("employeeList").disable();
			filterMentor();
		}
		if(dojo.widget.byId("mentorList").getText() != ""){
			dojo.widget.byId("mentorList").disable();
			filterMentee();
		}
	}
</script>

<script type="text/javascript">
	dojo.event.topic.subscribe("/ChangedMentor", function(value, key, text, widget){
		dojo.widget.byId("mentorList").disable();
		filterMentee();
	});
	
	dojo.event.topic.subscribe("/ChangedMentee", function(value, key, text, widget){
		dojo.widget.byId("employeeList").disable();
		filterMentor();
	});

	function filterMentee(){
		if(dojo.widget.byId("employeeList").getText() == ""){
			dojo.event.topic.publish('/RefreshMentee');
		}
		else{
		     actualizarLastMeetingDate();
		}
	}

	function filterMentor(){
		if(dojo.widget.byId("mentorList").getText() == ""){
			dojo.event.topic.publish('/RefreshMentor');
		}
		else{
			actualizarLastMeetingDate();
		}
	    var autoCompleter = dojo.widget.byId("mentorList");
	}

	function actualizarLastMeetingDate(){
		if(document.getElementById('stopRefresh').value == "true"){
			return;
		}
		var picker = dojo.widget.byId("lastMeetingDate");
	    if(picker != null){
	    	document.getElementById('stopRefresh').value = "true";
	   		document.getElementById('refresh').click();
	    }
    }

	function listOnlyCurrent() {
		filterMentee();
		filterMentor();
   	}
</script>

<s:url var="filterMentee" action="MentoringAction_filterMentee" namespace="/hrs2" />
<s:url var="filterMentor" action="MentoringAction_filterMentor" namespace="/hrs2" />

	<sx:autocompleter 
		id="mentorList"
		name="selectedMentorName" 
		href="%{#filterMentor}" 
		autoComplete="false"
		formId="mentorForm"
		listenTopics="/RefreshMentor"
		valueNotifyTopics="/ChangedMentor"
		forceValidOption="true" 
		key="mentor" 
		listValue="person.name"
		listKey="id" 
		searchType="startword"
		keyName="selectedMentorId" 
		showDownArrow="false"
		disabled="%{isEditing || onlyActualMentor}"
		required="%{areEmployeesRequired}"
		template="autocompleterHRS.ftl"
		templateDir="WEB-INF/template"
	    />
	    
	<sx:autocompleter 
		id="employeeList"
		name="selectedEmployeeName" 
		href="%{#filterMentee}"
		autoComplete="false" 
		formId="mentorForm"
		listenTopics="/RefreshMentee"
		valueNotifyTopics="/ChangedMentee"
		forceValidOption="true"
		key="mentee" 
		listValue="person.name"
		listKey="id" 
		searchType="startword" 
		showDownArrow="false" 
		keyName="selectedEmployeeId"
		disabled="%{isEditing}"
		required="%{areEmployeesRequired}"
		template="autocompleterHRS.ftl"
		templateDir="WEB-INF/template"
		/>

		<s:hidden id="stopRefresh" name="stopRefresh"></s:hidden>
